package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.LiveSquare.Adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Live.LiveSquare.ItemBean.Live;
import com.example.tnot.Util.ToastUtil;

import java.util.List;

public class rv_live_squareAdapter extends RecyclerView.Adapter<rv_live_squareAdapter.ViewHolder>{
    private List<Live> liveList;

    public rv_live_squareAdapter(List<Live> liveList) {
        this.liveList = liveList;
    }

    @NonNull
    @Override
    public rv_live_squareAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_live_square,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rv_live_squareAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.tv_description.setText(liveList.get(position).getDescription());
        holder.iv_photo.setImageResource(liveList.get(position).getPhoto());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.showCustomToast(v.getContext(),"点击了"+liveList.get(position).getDescription());
            }
        });
    }

    @Override
    public int getItemCount() {
        return liveList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_photo;
        TextView tv_description;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_photo = itemView.findViewById(R.id.iv_photo);
            tv_description = itemView.findViewById(R.id.tv_description);
        }
    }
}
